<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: banner_monthly.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */


require(DIR_WS_CLASSES . 'phplot.php');

$year = (($_GET['year']) ? $_GET['year'] : date('Y'));

$stats = array();
for ($i=1; $i<13; $i++) {
	$stats[] = array(strftime('%b', mktime(0,0,0,$i)), '0', '0');
}

$banner_stats = $db->db_query("	SELECT 
									MONTH(banners_history_date) AS banner_month, 
									SUM(banners_shown) AS value, 
									SUM(banners_clicked) AS dvalue 
								FROM 
									" . TABLE_BANNERS_HISTORY . " 
								WHERE 
									banners_id = '" . $banner_id . "' 
								AND 
									YEAR(banners_history_date) = '" . $year . "' 
								GROUP BY 
									banner_month");

while (!$banner_stats->EOF) {
	$stats[($banner_stats->fields['banner_month']-1)] = array(	strftime('%b', mktime(0,0,0,$banner_stats->fields['banner_month'])), 
																(($banner_stats->fields['value']) ? $banner_stats->fields['value'] : '0'), 
																(($banner_stats->fields['dvalue']) ? $banner_stats->fields['dvalue'] : '0'));
	$banner_stats->MoveNext();
}

$graph = new PHPlot(600, 350, 'images/graphs/banner_monthly-' . $banner_id . '.' . $banner_extension);

$graph->SetFileFormat($banner_extension);
$graph->SetIsInline(1);
$graph->SetPrintImage(0);

$graph->SetSkipBottomTick(1);
$graph->SetDrawYGrid(1);
$graph->SetPrecisionY(0);
$graph->SetPlotType('lines');

$graph->SetPlotBorderType('left');
$graph->SetTitleFontSize('4');
$graph->SetTitle(sprintf(TEXT_BANNERS_MONTHLY_STATISTICS, $banner->fields['banners_title'], $year));

$graph->SetBackgroundColor('white');

$graph->SetVertTickPosition('plotleft');
$graph->SetDataValues($stats);
$graph->SetDataColors(array('blue','red'),array('blue', 'red'));

$graph->DrawGraph();

$graph->PrintImage();
?>